package jschool.ui.Nomina;

import java.awt.Color;
import java.awt.Font;
import java.awt.Rectangle;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

import jschool.modelos.ModeloNomina;
import java.awt.Dimension;
import javax.swing.JToolBar;
import javax.swing.JButton;

public class PanelNomina extends JPanel {

	private static final long serialVersionUID = 1L;
	private JScrollPane jspNomina = null;
	private JTable tblNomina = null;
	private JLabel lblTitulo = null;
	private ModeloNomina modeloNomina = null;
	private float medida;
	private JToolBar toolBarBarra = null;
	private JLabel lblConfiguraciones = null;

	/**
	 * This is the default constructor
	 */
	public PanelNomina() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		modeloNomina = ModeloNomina.getInstancia();
		lblTitulo = new JLabel();
		lblTitulo.setBounds(new Rectangle(10, 46, 938, 18));
		lblTitulo.setText("Sistema de Nomina");
		lblTitulo.setHorizontalAlignment(SwingConstants.CENTER);
		lblTitulo.setForeground(Color.WHITE);
		lblTitulo.setBorder(BorderFactory.createLineBorder(Color.black, 1));
		lblTitulo.setOpaque(true);
		lblTitulo.setBackground(new Color(72, 129, 191));
		this.setSize(955, 109);
		this.setLayout(null);
		this.add(getJspNomina(), null);
		this.add(lblTitulo, null);
		this.add(getToolBarBarra(), null);
		int width = (int) (75 + medida);
		this.setSize(955, width);
	}

	/**
	 * This method initializes jspNomina
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getJspNomina() {
		if (jspNomina == null) {
			jspNomina = new JScrollPane();
			medida = 17.5f * (modeloNomina.getRowCount() + 1);
			jspNomina.setBounds(new Rectangle(10, 64, 939, (int) medida));
			jspNomina.setViewportView(getTblNomina());
		}
		return jspNomina;
	}

	/**
	 * This method initializes tblNomina
	 * 
	 * @return javax.swing.JTable
	 */
	private JTable getTblNomina() {
		if (tblNomina == null) {
			tblNomina = new JTable();
			tblNomina.setModel(modeloNomina);
			modeloNomina.disminuirColumna(tblNomina);
			tblNomina.setShowVerticalLines(false);
			tblNomina.setCellSelectionEnabled(false);
			tblNomina.setColumnSelectionAllowed(false);
			tblNomina.setFocusable(false);
			Color color = this.getBackground();
			tblNomina.setGridColor(color);
			DefaultTableCellRenderer tableRenderer = new DefaultTableCellRenderer();
			tableRenderer.setHorizontalAlignment(SwingConstants.CENTER);
			tblNomina.getColumnModel().getColumn(0).setCellRenderer(
					tableRenderer);
			tblNomina.getColumnModel().getColumn(1).setCellRenderer(
					tableRenderer);
		}
		return tblNomina;
	}

	/**
	 * This method initializes toolBarBarra
	 * 
	 * @return javax.swing.JToolBar
	 */
	private JToolBar getToolBarBarra() {
		if (toolBarBarra == null) {
			lblConfiguraciones = new JLabel();
			lblConfiguraciones.setText("Configuraciones");
			lblConfiguraciones.setFont(new Font("Dialog", Font.PLAIN, 12));
			lblConfiguraciones
					.addMouseListener(new java.awt.event.MouseAdapter() {
						public void mouseReleased(java.awt.event.MouseEvent e) {
							lblConfiguraciones.setFont(new Font("Dialog",
									Font.PLAIN, 12));
						}

						public void mousePressed(java.awt.event.MouseEvent e) {
							lblConfiguraciones.setFont(new Font("Dialog",
									Font.BOLD, 12));
						}

						public void mouseClicked(java.awt.event.MouseEvent e) {
							DialogoConfiguracionNomina dialogo = new DialogoConfiguracionNomina(
									null, "Configuraciones");
							dialogo.setVisible(true);
						}
					});
			lblConfiguraciones.setFocusable(false);
			toolBarBarra = new JToolBar();
			toolBarBarra.setMaximumSize(PanelNomina.this.getMaximumSize());
			toolBarBarra.setMinimumSize(PanelNomina.this.getMinimumSize());
			toolBarBarra.setAlignmentX(PanelNomina.this.getAlignmentX());
			toolBarBarra.setAlignmentY(PanelNomina.this.getAlignmentY());
			toolBarBarra.setBounds(new Rectangle(0, 0, 955, 28));
			toolBarBarra.add(lblConfiguraciones);
		}
		return toolBarBarra;
	}

} // @jve:decl-index=0:visual-constraint="10,10"
